{
  open Printf
  open Spiparser
}

let id = ['a'-'z'] ['a'-'z' 'A'-'Z' '0'-'9']*

rule spi_tokens = parse
  | [' ' '\t' '\n'] { spi_tokens lexbuf } (* Skip whitespaces *)
  | "begin"    { BEGIN }
  | "end"      { END }
  | '!'        { BANG }
  | '|'        { PAR }
  | "nil"      { NIL }
  | "ok"       { OK }
  | '('        { LPAREN }
  | ')'        { RPAREN }
  | '{'        { LBRACE }
  | '}'        { RBRACE }
  | ':'        { COLON }
  | ';'        { SCOLON }
  | ','        { COMMA }
  | "out"      { OUT }
  | "in"       { IN }
  | "new"      { NEW }
  | "decrypt"  { DECRYPT }
  | "split"    { SPLIT }
  | "match"    { MATCH }
  | "as"       { AS }
  | "pair"     { PAIR }
  | "Ch"       { CHAN }
  | "Un"       { UN }
  | "Key"      { KEY }
  | "Ok"       { TOK }
  | "Pair"     { TPAIR }
  | '*'        { UNKNOWN }
  | "Empty"    { EMPTY }
  | id as str  { ID str }
  | _ as c     { printf "Unrecognized character: %c\n" c; CHAR c}
  | eof        { raise End_of_file }
